/***************************************************************************
 创建者: 华磊
 开始时间: 2020.8.14
 copyright: (C) 华友高科
 修改说明: (每次有修改就添加一条，带有 修改人，修改时间，修改描述)
 example (1) hualei 2020.5.8 类的具体实现代码编写

 ***************************************************************************
 *  @file x.h
 *  功能:
 *
 *                                                                         *
 ***************************************************************************/
#ifndef ECATLOG_H
#define ECATLOG_H

#include <stdarg.h>
#include <stdio.h>
#include <iostream>

//#define CHECK_PARAMS(params, ...) {if(!checkSpecifiedParams(¶ms, __VA_ARGS__, "va_end"))return LOST_SPECIFIED_PARAM;}
//bool checkSpecifiedParams(const PARAMS*, ...);

struct S_MyLog{//printf or save
    int type;
    unsigned char msg[256];
};

//struct S_HmiLog{//for hmi
//    int id;
//    int robid;
//    int lv;
//    unsigned char componentName[64];
//    unsigned char string[256];
//};


//Message
using namespace std;
struct S_HmiLog {

//    int MessageLevel;
//    long time;
//    int robotId;
//    std::string componentClassName;
//    std::string messageType;
//    int messageCode;

//    int parameter1;
//    int parameter2;
//    int parameter3;
//    int parameter4;
//    std::string MessageInformation;

//public:
//    Message()
//    {
//        MessageLevel = (int)0;
//        time = (long)0;
//        robotId = (int)0;
//        messageCode = (int)0;
//        parameter1 = (int)0;
//        parameter2 = (int)0;
//        parameter3 = (int)0;
//        parameter4 = (int)0;
//    }

 };

/**
 * @brief The EcatLog class  消息类
 */
class EcatLog
{
public:
    EcatLog();
    void init(){}

    void error(const char* fmt, ... );
    void message(const char* fmt, ... );

    void addMsg( int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 int parameter1 = 0,
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0 );

    /**
     * @brief clearMessage
     * @param msg
     * @return   , 0=ok
     */
    int clearMessage( S_HmiLog msg );

    void addMessage( const char* fmt, ... );
    void addError( const char* fmt, ... );
    void addMessage(int id , const char* fmt, ... );
    void addError(int id , const char* fmt, ... );

    void show();
 //   void processMsg(){}

private:


    unsigned char current_pos;
    unsigned char avriable_cout;
    S_MyLog mlog[256];//for log


    unsigned char start_pos_hmi;
    unsigned char current_pos_hmi;
    unsigned char available_cout_hmi;
    S_HmiLog ulog[256];//for hmi
    int available[256];//for hmi

};

#endif // ECATLOG_H
